<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="books.storage.service.*"%>
<%@ page import="books.borrowing.entity.*"%>
<%@ page import="java.util.List"%>
<!DOCTYPE html>
<html>
<head>
<title>ELibrary - Accueil</title>
<script src="js/jquery-1.6.4.min.js">
	
</script>
<script src="js/jquery.mobile-1.0rc2.min.js">
	
</script>

<link rel="stylesheet" type="text/css"
	href="jquery.mobile-1.0rc2.min.css" />
<meta name="viewport"
	content="width=device-width, minimum-scale=1, maximum-scale=1">
</head>
<body style="width: 450px;">
	<div data-role="page">

		<div data-role="header">
			<h1>ELibrary</h1>

		</div>
		<!-- /header -->

		<div data-role="content">
			<%
				String search_field = (session.getAttribute("search_field") != null) ? (String) session
						.getAttribute("search_field") : "";
			%>
			<form method="post" action="mcatalog">
				<h3>Chercher un livre par titre</h3>
				<input type="text" name="search_field" value="<%=search_field%>" />
				<input type="submit" value="Rechercher" />
			</form>
			<br /> <br />

			<%
				List<BookDto> bookList = (List<BookDto>) session
						.getAttribute("bookList");

				out.println("<ul data-role='listview'>");
				for (BookDto book : bookList) {
					LiteraryGenreDto lgd = book.getLiterary();
					out.println("<li>");
					out.println("<a href='#'>");
					out.println("<span style='font-size:20px;'>" + book.getTitle()
							+ "<br/>de " + book.getAuthor().getName() + "</span>");

					out.println("<img src='images/books/" + book.getIsbn()
							+ ".jpg'>");

					SubscriberEntity user = (SubscriberEntity) session
							.getAttribute("user");
					if (user == null) {
						out.println("<p style='color:red; font-weight:bold;'>Connectez vous pour louer ce livre</p>");
					} else if (book.getCopiesNumber() < 1) {
						out.println("<p style='color:red; font-weight:bold;'>Ce livre n'est plus dispnonible</p>");
					} else {
						out.println("<form method='post' action='rent'>");
						out.println("<input type='hidden' name='user_action' value='rent_on' />");
						out.println("<input type='hidden' name='book_isbn' value='"
								+ book.getIsbn() + "' />");
						out.println("<input type='hidden' name='user_login' value='"
								+ user.getLogin() + "' />");
						out.println("<input type='submit' value='Louer ce livre'>");
						out.println("<p style='color:green; font-weight:bold;'>Encore "
								+ book.getCopiesNumber()
								+ " copies dispnonibles</p>");
						out.println("</form>");
					}

					out.println("</a>");
					out.println("</li>");
				}
				if (bookList.size() == 0) {
					out.println("<p style='color:red; font-size:20px;'>Aucun exemplaire à afficher</p>");
				}

				out.println("</ul>");
			%>
		</div>
		<!-- /content -->

		<div data-role="footer" class="ui-state-persist ui-btn-active">
			<div data-role="navbar">
				<ul>
					<li><a rel="external" href="mhome">Accueil</a></li>
					<li><a href="#" class="ui-btn-active">Catalogue</a></li>
				</ul>
			</div>
			<!-- /navbar -->
		</div>
		<!-- /footer -->

	</div>
	<!-- /page -->

</body>
</html>